package com.ruoyi.iot.service.impl;

import com.ruoyi.iot.domain.Agent;
import com.ruoyi.iot.mapper.IotMapper;
import com.ruoyi.iot.service.IIotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @ClassName IotServiceImpl
 * @Description TODO
 * @Author hly
 * @Date 2024/1/14 14:56
 */
@Service
public class IotServiceImpl implements IIotService {
    @Autowired
    private IotMapper iotMapper;

    @Override
    public List<Agent> listAgent(String name) {
        return iotMapper.listAgent(name,"like");
    }

    public List<Agent> listAgentAccurate(String name) {
        return iotMapper.listAgent(name,"accurate");
    }

    @Override
    public List<Agent> getAgentListByIds(List<Integer> ids) {
        return iotMapper.getAgentListByIds(ids);
    }

    public List<Agent> findAgents(List<String> names) {
        return iotMapper.findAgents(names);
    }

    @Override
    public List<Agent> agentChilds(String name) {
        //精确查询
        List<Agent> list  = iotMapper.listAgent(name,"accurate");
        if (list.isEmpty()) {
            throw new RuntimeException("该用户不是物联卡系统代理用户,无法使用此功能");
        }
        Agent map = list.get(0);
        List<Integer> ids = iotMapper.findAgentChilds(map.getId());
        if (ids.isEmpty()) {
            return Collections.emptyList();
        }
        List<Agent> maps = iotMapper.getAgentListByIds(ids);
        return maps;
    }


}
